//
//  UserFinanceViewController.m
//  XinKaiFa55like
//
//  Created by junseek on 2017/3/24.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "UserFinanceViewController.h"
#import "RHTableView.h"
#import "UserFinanceTableViewCell.h"
#import "UILabel+atrribulttext.h"
#import "UserFinanceChartViewController.h"

@interface UserFinanceViewController ()<RHTableViewDelegate>{
    RHTableView *table_user;
    UILabel *lblMoney1;
    UILabel *lblMoney2;
    UILabel *lblMoney3;
    
}

@end

@implementation UserFinanceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self rightButton:nil image:@"headqxt" sel:@selector(rightBUttonClicked)];
    
    [self initTopHeaderView];
    [self initTabelViews];
    
    [self loadTableData];
}
-(void)initTopHeaderView{
    UIView *viewHeader=[[UIView alloc] initWithFrame:CGRectMake(0, kTopHeight, kScreenWidth, 140)];
    viewHeader.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:viewHeader];
    float fw=(kScreenWidth-60)/3;
    
    [viewHeader addSubview:[RHMethods lineViewWithFrame:CGRectMake(10, 45, fw, 3)]];
    [viewHeader addSubview:[RHMethods lineViewWithFrame:CGRectMake(30+fw, 45, fw, 3)]];
    [viewHeader addSubview:[RHMethods lineViewWithFrame:CGRectMake(50+fw*2, 45, fw, 3)]];
    
    lblMoney1=[RHMethods labelWithFrame:CGRectMake(10, 25, fw, 40) font:fontTitle color:rgbTitleColor text:@"123.29" textAlignment:NSTextAlignmentCenter];
    [viewHeader addSubview:lblMoney1];
    
    
    lblMoney2=[RHMethods labelWithFrame:CGRectMake(30+fw, 25, fw, 40) font:fontTitle color:rgbTitleColor text:@"13.20" textAlignment:NSTextAlignmentCenter];
    [viewHeader addSubview:lblMoney2];
    
    
    lblMoney3=[RHMethods labelWithFrame:CGRectMake(50+fw*2, 25, fw, 40) font:fontTitle color:rgbTitleColor text:@"123.25" textAlignment:NSTextAlignmentCenter];
    [viewHeader addSubview:lblMoney3];
    
    lblMoney1.adjustsFontSizeToFitWidth=YES;
    lblMoney2.adjustsFontSizeToFitWidth=YES;
    lblMoney3.adjustsFontSizeToFitWidth=YES;
    lblMoney1.font=[UIFont fontWithName:@"Arial Rounded MT Bold" size:35];
    lblMoney2.font=[UIFont fontWithName:@"Arial Rounded MT Bold" size:35];
    lblMoney3.font=[UIFont fontWithName:@"Arial Rounded MT Bold" size:35];
    
    
    UILabel *lblTitle1=[RHMethods labelWithFrame:CGRectMake(10, YH(lblMoney1), fw, 20) font:fontTxtContent color:rgbTxtDeepGray text:@"业绩(万)" textAlignment:NSTextAlignmentCenter];
    [lblTitle1 setColor:rgbBlue contenttext:@"业绩"];
    [viewHeader addSubview:lblTitle1];
    
    UILabel *lblTitle2=[RHMethods labelWithFrame:CGRectMake(30+fw, YH(lblMoney1), fw, 20) font:fontTxtContent color:rgbTxtDeepGray text:@"支出(万)" textAlignment:NSTextAlignmentCenter];
    [lblTitle2 setColor:RGBCOLOR(0, 165, 99) contenttext:@"支出"];
    [viewHeader addSubview:lblTitle2];
    
    UILabel *lblTitle3=[RHMethods labelWithFrame:CGRectMake(50+fw*2, YH(lblMoney1), fw, 20) font:fontTxtContent color:rgbTxtDeepGray text:@"利润(万)" textAlignment:NSTextAlignmentCenter];
    [lblTitle3 setColor:[UIColor redColor] contenttext:@"利润"];
    [viewHeader addSubview:lblTitle3];
    
    UIView *viewTitleBG=[[UIView alloc] initWithFrame:CGRectMake(0, 100, kScreenWidth, 40)];
    viewTitleBG.backgroundColor=rgbGray;
    [viewHeader addSubview:viewTitleBG];
    
    [viewTitleBG addSubview:[RHMethods lineViewWithFrame:CGRectMake(0, 0, kScreenWidth, 0.5)]];
    [viewTitleBG addSubview:[RHMethods lineViewWithFrame:CGRectMake(0, 39.5, kScreenWidth, 0.5)]];
    
    float fw2=(kScreenWidth)/4;
    [viewTitleBG addSubview:[RHMethods labelWithFrame:CGRectMake(0, 0, fw2, 40) font:fontTxtContent color:rgbTxtDeepGray text:@"月份" textAlignment:NSTextAlignmentCenter]];
    [viewTitleBG addSubview:[RHMethods labelWithFrame:CGRectMake(fw2, 0, fw2, 40) font:fontTxtContent color:rgbTxtDeepGray text:@"业绩" textAlignment:NSTextAlignmentCenter]];
    [viewTitleBG addSubview:[RHMethods labelWithFrame:CGRectMake(fw2*2, 0, fw2, 40) font:fontTxtContent color:rgbTxtDeepGray text:@"支出" textAlignment:NSTextAlignmentCenter]];
    [viewTitleBG addSubview:[RHMethods labelWithFrame:CGRectMake(fw2*3, 0, fw2, 40) font:fontTxtContent color:rgbTxtDeepGray text:@"利润" textAlignment:NSTextAlignmentCenter]];
    
    
}
-(void)initTabelViews{
    table_user=[[RHTableView alloc]initWithFrame:CGRectMake(0, kTopHeight+140, kScreenWidth, kContentHeight-140)];
    [table_user showRefresh:YES LoadMore:YES];
    table_user.delegate = self;
    table_user.dataSource = self;
    table_user.delegate2=self;
    [table_user setBackgroundColor:rgbGray];
    [table_user setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:table_user];
    [table_user setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
    [table_user registerClass:[UserFinanceTableViewCell class] forCellReuseIdentifier:@"UserFinanceTableViewCell"];
}



-(void)loadTableData{
    krequestParam
    [dictparam setValue:@"%@" forKey:@"page"];
    [dictparam setValue:@"20" forKey:@"pagesize"];
    [dictparam setValue:@"1" forKey:@"type"];//（1 个人按月排行  2曲线图）默认显示1    
    table_user.urlString=[NSString stringWithFormat:@"%@%@",XKFV3usermyamoeba,dictparam.wgetParamStr];
    [table_user refresh];
}
#pragma mark RHTableViewDelegate
-(void)refreshData:(RHTableView *)view{
    if (view.dataDic) {
        lblMoney1.text=[view.dataDic valueForJSONStrKey:@"totalperformance"];
        lblMoney2.text=[view.dataDic valueForJSONStrKey:@"totalexpend"];
        lblMoney3.text=[view.dataDic valueForJSONStrKey:@"totalprofit"];
    }
}
#pragma mark button
-(void)rightBUttonClicked{
    [self pushController:[UserFinanceChartViewController class] withInfo:@"" withTitle:@" " withOther:nil];
}
#pragma mark tableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return table_user.dataArray.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic=[table_user.dataArray objectAtIndex:indexPath.row];
    UserFinanceTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"UserFinanceTableViewCell" forIndexPath:indexPath];
    [cell setValueForDictionary:dic indexPath:indexPath type:self.userInfo];
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
